<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/component/pear/css/pear.css"/>
    <link rel="stylesheet" href="/component/layui/css/layui.css">
    <style>
        .layui-anim{
            max-height: 240px !important;
        }
    </style>
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">用户部门</label>
                    <div class="layui-input-block">
                        <select name="deptId" lay-search lay-filter="deptId" lay-verify="required"
                                lay-reqtext="部门为必填项">
                            <option value="">请选择部门</option>
                            <option th:each="dept:${myDeptList}" th:value="${dept.getDeptId()}" th:text="${dept.getDeptName()}">
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">机柜</label>
                    <div class="layui-input-block">
                        <select name="number" lay-search lay-filter="number" lay-verify="required"
                                lay-reqtext="机柜为必填项">
                            <option value="">请选择机柜</option>
                            <option th:each="number:${numberList}" th:value="${number}" th:text="${number}">
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">开始编号</label>
                    <div class="layui-input-block">
                        <select name="startNumber" id="startNumber" lay-search lay-verify="required"
                                lay-reqtext="开始编号为必填项">
                            <option value="">请选择开始编号</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">结束编号</label>
                    <div class="layui-input-block">
                        <select name="endNumber" id="endNumber" lay-search lay-verify="required"
                                lay-reqtext="结束编号为必填项">
                            <option value="">请选择结束编号</option>
                            <option th:each="number:${numberList}" th:value="${number}" th:text="${number}">
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">责任人</label>
                    <div class="layui-input-block">
                        <select name="userId" id="userId" lay-search lay-verify="required"
                                lay-reqtext="用户名为必填项">
                            <option value="">请选择用户</option>
                            <option th:each="user:${myUserList}" th:value="${user.getUserId()}" th:text="${user.getUserName()}">
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="role-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="/component/layui/layui.js"></script>
<script src="/component/pear/pear.js"></script>
<script>
    layui.use([ 'form', 'jquery'], function () {
        let form = layui.form;
        let $ = layui.jquery;

        form.on('select(number)', function (data) {
            var value = data.value;
            let insertHtml = '<option value="">请选择开始编号</option>';
            $.get("/dept/cabinet/add/door/count", {"number": value}, function (data) {
                for (index in data) {
                    insertHtml += '<option value="' + data[index] + '">' + data[index] + '</option>';
                }
                $("#startNumber").html(insertHtml);
                $("#endNumber").html(insertHtml);
                form.render('select');
            });

        });

        form.on('submit(role-save)', function (data) {
            // 获取复选框数组数据
            var data = data.field
            let loading = layer.load();
            $.ajax({
                url: '/dept/cabinet/add/save',
                data: JSON.stringify(data),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    layer.close(loading);
                    if (result.code == 200) {
                        layer.msg(result.message, {icon: 1, time: 2000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("testReload");
                        });
                    } else {
                        layer.msg(result.message, {icon: 2, time: 2000});
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>